<?php
class Administrator_Model_Component extends Administrator_Model_System {
	public function __construct() {
		$this->lang = new Nguyen_language_system ();
		$this->db = Zend_Registry::get ( 'vicdbsystem' );
	}
	public function GetAllComponent() {
		$sql = 'select * from controller';
		return $this->db->fetchAll ( $sql );
	}
	public function GetComponentInfo($id) {
		$sql = 'select * from controller where id="' . $id . '"';
		return $this->db->fetchRow ( $sql );
	}
	public function InsertComponent($name, $display) {
		$data = array ('name' => $name, 'display' => $display );
		$this->db->insert ( 'controller', $data );
		return $this->db->lastInsertId ();
	}
	public function UpdateComponent($id, $name, $display) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'display' => $display );
		$this->db->update ( 'controller', $data, $where );
	}
	public function DelComponent($id) {
		if ($this->countActioninComponent ( $id ) > 0)
			return;
		$where = "id='" . $id . "'";
		$this->db->delete ( 'controller', $where );
	}
	public function countActioninComponent($id) {
		$sql = 'select * from action where controller="' . $id . '"';
		return count ( $this->db->fetchAll ( $sql ) );
	}
	// ///action//////////////////////////////////
	public function GetAllAction() {
		$sql = 'select * from action';
		return $this->db->fetchAll ( $sql );
	}
	public function InsertAction($name, $display, $controller) {
		$data = array ('name' => $name, 'display' => $display, 'controller' => $controller );
		$this->db->insert ( 'action', $data );
		return $this->db->lastInsertId ();
	}
	public function UpdateAction($id, $name, $display, $controller) {
		$where = "id='" . $id . "'";
		$data = array ('name' => $name, 'display' => $display, 'controller' => $controller );
		$this->db->update ( 'action', $data, $where );
	}
	public function countViewinAction($id) {
		$sql = 'select * from view where action="' . $id . '"';
		return count ( $this->db->fetchAll ( $sql ) );
	}
	public function DelAction($id) {
		if ($this->countViewinAction ( $id ) > 0)
			return;
		$where = "id='" . $id . "'";
		$this->db->delete ( 'action', $where );
	}
	public function GetActionInfo($id) {
		$sql = 'select * from action where id="' . $id . '"';
		return $this->db->fetchRow ( $sql );
	}
	// /////////////////////view///////////////////////////////////
	public function GetAllView() {
		$sql = 'select * from view';
		return $this->db->fetchAll ( $sql );
	}
	public function GetAllViewByAddon($id) {
		$sql = 'select * from view where action='.$id;
		return $this->db->fetchAll ( $sql );
	}
	public function InsertView($name, $display, $action) {
		$data = array ('name' => $name, 'display' => $display, 'action' => $action );
		$this->db->insert ( 'view', $data );
		return $this->db->lastInsertId ();
	}
	public function UpdateView($id, $name, $display, $action) {
		$where = "id='" . $id . "'";
		$data = array ('name' => $name, 'display' => $display, 'action' => $action );
		$this->db->update ( 'view', $data, $where );
	}
	public function DelView($id) {
		$where = "id='" . $id . "'";
		$this->db->delete ( 'view', $where );
	}
	public function GetViewInfo($id) {
		$sql = 'select * from view where id="' . $id . '"';
		return $this->db->fetchRow ( $sql );
	}

}